package config

import (
	"context"
	"fmt"

	"rdbmsx/config"

	influxdb2 "github.com/influxdata/influxdb-client-go/v2"
)

func Client() influxdb2.Client {
	client := influxdb2.NewClientWithOptions(
		config.InfluxHost,
		config.InfluxToken,
		config.InfluxDBOpt.Option(),
	)
	ctx := context.Background()

	ping, err := client.Ping(ctx)
	if err != nil {
		return nil
	}

	fmt.Println(ping)

	health, err := client.Health(ctx)
	if err != nil {
		panic(err)
	}

	fmt.Println(health.Name, *health.Message, *health.Version)

	return client
}
